package com.ruoyi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.po.Account;
import com.ruoyi.service.IAccountService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 外部账号 前端控制器
 * @author 杨宸
 * @date 2025-02-12
 */
@RestController
@RequestMapping("/account")
@Api(tags = {"外部账号控制器"})
public class AccountController {

    /**
     * 外部账号业务接口
     */
    @Autowired
    private IAccountService baseService;

    /**
     * 描述：分页查询
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "分页查询")
    public R<IPage<Account>> pageList(@RequestBody Account account) {
        IPage<Account> pageVo = baseService.pageList(account);
        return R.ok(pageVo);
    }
    
    /**
     * 描述：详情
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/detail")
    @ApiOperation(value = "详情")
    public R<Account> detailAccount(@RequestBody Long id) {
        Account account = baseService.detailAccount(id);
        return R.ok(account);
    }    

    /**
     * 描述：保存
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/saveAccount")
    @ApiOperation(value = "保存")
    @Log(title = "外部账号管理", businessType = BusinessType.INSERT)
    public R<String> saveAccount(@RequestBody Account account) {
        baseService.saveAccount(account);
        return R.ok("保存成功！");
    }

    /**
     * 描述：修改
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/updateAccount")
    @ApiOperation(value = "修改")
    @Log(title = "外部账号管理", businessType = BusinessType.UPDATE)
    public R<String> updateAccount(@RequestBody Account account) {
        baseService.updateAccount(account);
        return R.ok("修改成功！");
    }

    /**
     * 描述：删除
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/deleteAccount")
    @ApiOperation(value = "删除")
    @Log(title = "外部账号管理", businessType = BusinessType.DELETE)
    public R<String> deleteAccount(@RequestBody List<Long> ids) {
        baseService.deleteAccount(ids);
        return R.ok("删除成功！");
    }

    /**
     * 描述：批量导出
     * @author 杨宸
     * @date 2025-02-12
     */
    @PostMapping("/exportExcel")
    @ApiOperation(value = "批量导出")
    @Log(title = "外部账号管理", businessType = BusinessType.EXPORT)
    public void exportExcel(HttpServletResponse response, @RequestBody Account account) {
        baseService.exportExcel(response, account);
    }

    /**
     * 描述：获得图形验证码
     * @author Cymal
     * @date 2024-06-29
     */
//    @PostMapping("/getImgCode")
//    @ApiOperation(value = "获得图形验证码")
//    public AjaxResult getImgCode(HttpServletResponse response) {
//        return baseService.getImgCode(response);
//    }

}
